/**
 * <p>Title: DropableObstacle.java</p>
 * <p>Description: CS 343 Final Project. This class contains the droppable object from the eagle</p>
 * @author Tim Olmstead, Brady Fetting, Erik Brown, Thales Kirk
 * @email timothy.olmstead@my.uwrf.edu, brady.fetting@my.uwrf.edu, 
 * 			erik.brown@my.uwrf.edu, thales.kirk@my.uwrf.edu
 * @date November 15, 2013
 */
package Obstacles;

import java.awt.Image;
import java.awt.Polygon;

import javax.swing.ImageIcon;

import GameState.Game;

public class DropableObstacle extends Obstacle {

	private Image sprite;
	private boolean dropped;

	/**
	 * 
	 * @param x
	 * @param y
	 * @param width
	 * @param height
	 * @description creates the droppable object
	 */
	public DropableObstacle(int x, int y, int width, int height) {
		super(x, y, width, height);
		sprite = new ImageIcon("src/images/beeHive.png").getImage();
		dropped = false;
		// set sprites

	}

	/**
	 * @param none
	 * @description sets drop to true
	 */
	public void drop() {
		dropped = true;

	}

	/**
	 * @param none
	 * @description creates the dropable obstacle to be used in the game and
	 *              sets drop to false
	 */
	public DropableObstacle() {
		super(-90, 130, 10, 10);
		sprite = new ImageIcon("src/images/beeHive.png").getImage();
		setHeight(sprite.getHeight(null));
		setWidth(sprite.getWidth(null));
		dropped = false;
	}

	@Override
	/**
	 * @param none
	 * @description returns the image of the sprite
	 */
	public synchronized Image getImage() {
		return sprite;
	}

	@Override
	/**
	 * @param none
	 * @description controls the movement of the droppable object
	 */
	public synchronized void move() {
		if (!dropped)
			super.setXloc(super.getXloc() + 3);
		else if (dropped && getYloc() < Game.getGroundLevel() + 80)
			setYloc(getYloc() + 3);
		else {
			super.setXloc(super.getXloc() - Game.getGameSpeed());
			setYloc(Game.getGroundLevel() + 80);
		}
	}

	@Override
	/**
	 * @param none
	 * @description gets the polygon dimensions of the droppable object for collision detection
	 */
	public Polygon getPolygon() {
		int[] xs = new int[5];
		int[] ys = new int[5];
		xs[0] = getXloc() + 0;
		ys[0] = getYloc() + 9;
		xs[1] = getXloc() + 39;
		ys[1] = getYloc() + 18;
		xs[2] = getXloc() + 15;
		ys[2] = getYloc() + 37;
		xs[3] = getXloc() + 5;
		ys[3] = getYloc() + 35;
		xs[4] = getXloc() + 3;
		ys[4] = getYloc() + 20;
		return new Polygon(xs, ys, xs.length);
	}

	/**
	 * @param none
	 * @description returns the value if the object has been dropped
	 */
	public boolean isDropped() {
		return dropped;
	}

	/**
	 * @param dropped
	 * @description sets whether the object has been dropped or not
	 */
	public void setDropped(boolean dropped) {
		this.dropped = dropped;
	}

}
